<template>
	<view>
		<view class="fw-b ft_18 navbar">
			个人中心
		</view>
		<view class="content">
			<view class="con_1 card display just_space" v-if="$all.getData('user')">
				<view class="display">
					<view class="p_right_10">
						<image :src="userInfo.avatar"></image>
					</view>
					<view class="">
						<view class="p_bottom_10 ft_18 fw-b">
							{{userInfo.username}}
						</view>
						<view class="ft_12 vip">
							{{userInfo.level}} 
						</view>
					</view>
				</view>
				<view class="c-999" @click="editUserinfo">
					修改个人信息
					<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
				</view>
			</view>
			<view class="con_1 card display" v-else>
				<view class="p_right_10">
					<image :src="userInfo.avatar"></image>
				</view>
				<view class="p_bottom_10 ft_18 fw-b" @click="is_login">
					{{userInfo.username}}
				</view>
			</view>
			
			<view class="con_2 card">
				<view class="display just_space" style="padding-bottom: 20px;">
					<view class="">
						我的订单
					</view>
					<view class="ft_12 c-999" @click="go_order(0)">
						查看
						<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
					</view>
				</view>
				<view class="display just_space">
					<view v-for="(item,index) in orderClass" :key="index" class="orderclass" @click="go_order(index+1)">
						<image :src="item.icon"></image>
						<view class="ft_12 c-999">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
			<view class="con_3 card display just_space">
				<view style="position: relative;" v-for="(item,index) in others" :key="index" class="other" @click="go_other(index)">
					<image :src="item.icon" :class="index==0||index==1?'image1':index==5?'image2':''"></image>
					<view class="ft_12 c-999">
						{{item.title}}
					</view>
					<view v-if="index==6&&userInfo.notice>0" class="" style="width: 8px;height: 8px;background-color: red;border-radius: 50%;position: absolute;right: 20px;top: 0;"></view>
				</view>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:{
					avatar:'../../static/login/avatar.png',
					username:"点击登录"
				}, //用户信息
				orderClass:[ //订单类别
					{
						icon:"/static/mine/mine/daipay.png",
						title:'待支付'
					},
					{
						icon:"/static/mine/mine/daifh.png",
						title:'待发货'
					},
					{
						icon:"/static/mine/mine/daish.png",
						title:'待收货'
					},
					{
						icon:"/static/mine/mine/yiwc.png",
						title:'已完成'
					},
				],
				others:[ //其他跳转
					{
						icon:'/static/mine/mine/huiyuan.png',
						title:"会员中心"
					},
					{
						icon:'/static/mine/mine/jingxiao.png',
						title:"门店中心"
					},
					{
						icon:'/static/mine/mine/saoma.png',
						title:"核销"
					},
					{
						icon:'/static/mine/mine/pinzheng.png',
						title:"上传凭证"
					},
					{
						icon:'/static/mine/mine/yuyue.png',
						title:"预约"
					},
					{
						icon:'/static/mine/mine/youhui.png',
						title:"优惠券"
					},
					{
						icon:'/static/mine/mine/xiaoxi.png',
						title:"系统消息"
					},
					{
						icon:'/static/mine/mine/shoucang.png',
						title:"我的收藏"
					},
					{
						icon:'/static/mine/mine/lishi.png',
						title:"浏览历史"
					},
					{
						icon:'/static/mine/mine/ruzhu.png',
						title:"申请入驻"
					},
					{
						icon:'/static/mine/mine/dizhi.png',
						title:"收货地址"
					},
					{
						icon:'/static/mine/mine/shezhi.png',
						title:"设置"
					},
				],
				
			}
		},
		onLoad() {
			uni.$on('userinfo',res=>{
				this.getuserInfo() //获取用户信息
			})
		},
		onShow() {
			if(uni.getStorageSync("user")){
				this.getuserInfo() //获取用户信息
			}
		},
		methods: {
			is_login(){ //判断是否登录
				// #ifdef MP-WEIXIN
				if(!uni.getStorageSync("user")){
					this.$all.toast("请登录后操作")
					setTimeout(()=>{
						uni.reLaunch({
							url:"../../mine/pages/login/login"
						})
					},500)
					return false;
				}else{
					return true;
				}
				// #endif
				// #ifndef MP-WEIXIN
				return true;
				// #endif
			},
			getuserInfo(){ //获取用户信息
				this.$myRequest('user/index',{})
				.then(res=>{
					console.log(res.data.data);
					if(res.data.code==1){
						this.userInfo=res.data.data.info
					}
				})
			},
			
			editUserinfo(){ //修改用户信息
				if(!this.is_login()) return  //未登录 去登录
				uni.navigateTo({
					url:"/mine/pages/mine/editUserinfo"
				})
			},
			go_order(index){ //查看订单列表
				if(!this.is_login()) return  //未登录 去登录
				console.log(index);
				uni.navigateTo({
					url:"/mine/pages/mine/orders/myOrder?type="+index
				})
			},
			go_other(index){ //跳转其他页
				if(!this.is_login()) return  //未登录 去登录
				switch (index){
					case 0: //会员中心
						uni.navigateTo({
							url:"../../mine/pages/mine/others/VipCore"
						})
					break;
					case 1: //门店中心
						if(this.userInfo.role_type!=0){
							uni.navigateTo({
								url:"../../mine/pages/mine/others/jingxiaoCore/jingxiaoCore"
							})
						}else{
							this.$all.toast("未入驻")
						}
					break;
					case 2: //扫码核销
						if(this.userInfo.role_type==3){ //体彩店
							uni.navigateTo({
								url:"../../mine/pages/mine/others/saomaHX"
							})
						}else{
							this.$all.toast("未入驻体彩店")
						}
					break;
					case 3: //上传凭证
						if(this.userInfo.role_type==3){ //体彩店
							uni.navigateTo({
								url:"../../mine/pages/mine/others/upPingzheng"
							})
						}else{
							this.$all.toast("未入驻体彩店")
						}
					break;
					case 4: //预约
						this.$all.toast('暂未开放')
						return
						uni.navigateTo({
							url:"../../mine/pages/index/yuyue"
						})
					break;
					case 5: //优惠券
						uni.navigateTo({
							url:"../../mine/pages/mine/others/coupon"
						})
					break;
					case 6: //系统消息
						uni.navigateTo({
							url:"../../mine/pages/mine/others/systemNew"
						})
					break;
					case 7: //我的收藏
						uni.navigateTo({
							url:"../../mine/pages/mine/others/myCollection"
						})
					break;
					case 8: //浏览记录
						uni.navigateTo({
							url:"../../mine/pages/mine/others/browseJilu"
						})
					break;
					case 9: //申请入驻
						if(this.userInfo.role_type==0){ //普通用户
							if(this.userInfo.is_role==0){ //是否有申请状态
								let list=['入驻体彩店','入驻门店','入驻经销商']
								uni.showActionSheet({
									itemList: list,
									success: res => {
										let type=res.tapIndex
										uni.navigateTo({
											url:"../../mine/pages/mine/others/applyRuzhu?type="+type
										})
									},
									fail: () => {},
									complete: () => {}
								});
							}else{
								this.$all.toast("已申请，请耐心等待审核！")
							}
						}else if(this.userInfo.role_type==1){
							this.$all.toast("已入驻经销商")
						}else if(this.userInfo.role_type==2){
							this.$all.toast("已入驻门店")
						}else{
							this.$all.toast("已入驻体彩店")
						}
						
					break;
					case 10: //收货地址
						uni.navigateTo({
							url:"../../mine/pages/mine/shAddress"
						})
					break;
					case 11: //设置
						uni.navigateTo({
							url:"../../mine/pages/mine/others/setup/setUp"
						})
					break;
				}
			},
			
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fafafa;
	}
	.navbar{
		padding: 40px 15px 0;
	}
	.content{
		padding: 15px;
		.card{
			padding: 20px;background-color: #FFFFFF;
			border-radius: 10rpx;
		}
		.con_1{
			margin-bottom: 10px;
			image{
				width: 60px;height: 60px;border-radius: 50%;
				background-color: #dddddd;
			}
			.vip{
				color: #E67920;border: 1px solid #E67920;padding: 2px 10px;border-radius: 20px;
				text-align: center;
			}
		}
		.con_2{
			margin-bottom: 10px;
			.orderclass{
				width: 20%;text-align: center;
			}
			image{
				width: 20px;height: 18px;margin-bottom: 5px;
			}
		}
		.con_3{
			margin-bottom: 10px;
			flex-flow: wrap;
			.other{
				width: 21%;text-align: center;
				margin-bottom: 20px;
			}
			image{
				margin-bottom: 5px;
				width: 20px;height: 20px;	
			}
			.image1{
				width: 22px;height: 20px;
			}
			
			.image2{
				width: 22px;height: 18px;
			}
		}
		
	}
	
</style>
